/////////////////////////////////////任意点的处理函数//////////////////////////////////
function initForRyd(){
	gpsTimeInit(1);
	getWeizhiByFlag(1);
}

function rydQxButtonClick(){
	top.wodeweizhiDlg.close();
}


function rydQdButtonClick(){
	var jd = $("#rydJd").val();
	var wd = $("#rydWd").val();
	var gd = $("#rydGd").val();
	var dwsj = $("#rydDwsj").val();
	var mc = $("#rydDmc").val();
	if(jd==""||wd==""||gd==""||dwsj==""||mc==""){
		alert("数据填入不完整!");
		return;
	}
	var obj = {jd:jd,wd:wd,gd:gd,dwsj:dwsj,mc:mc};
	var url ="insertWdwzForRyd.shtml";
	$.post(url,obj,function(res){
		if(res=="true"){
			alert("插入成功!");
		}else{
			alert("插入失败!");
		}
	})
}


/////////////////////////////////二者公用的函数///////////////////////////////////////////
//分、秒的补偿函数
function checkTime(i)
{
	if (i<10) 
	  {i="0" + i}
	  return i
}

//初始化对话框，对时间进行操作
function gpsTimeInit(flag){
	var date = new Date();
	//对日期赋值
	var dateStr = date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日"+date.getHours()+"时"+checkTime(date.getMinutes())+"分"+checkTime(date.getSeconds())+"秒";
	if(flag){
		$("#rydDwsj").attr("value",dateStr).attr("disabled","disabled");
	}else{
		$("#zhdnDwsj").attr("value",dateStr).attr("disabled","disabled");
	}
	t1 = setTimeout('gpsTimeInit('+flag+')',500);
}

function getWeizhiByFlag(flag){
	var url = "Getjwd.shtml";
	$.post(url,null,function(res){
		wodeweizhiCallback(res,flag);
	});
}

function wodeweizhiCallback(res,flag){
	if(res=="0.0,0.0,0.0"){
		alert("gps没有获取当前位置!");
		return;
	}
	var jd = res.split(",")[0];
	var wd = res.split(",")[1];
	var gd = res.split(",")[2];
	//打上mark标
	top.createWodeweizhiMark(jd,wd);
	//填充数据
	if(flag){
		$("#rydJd").val(jd);
		$("#rydWd").val(wd);
		$("#rydGd").val(gd);
	}else{
		$("#zhdnJd").val(jd);
		$("#zhdnWd").val(wd);
		$("#zhdnGd").val(gd);
	}
	
}

////////////////////////////////灾害点内定位////////////////////////////////////////

function initForZhdn(){
	gpsTimeInit(0);
	getWeizhiByFlag(0);
}

//对话框模糊查询灾害点
function getYJDCDForZhdnByKeyword(){
	var keyword = $("#zhdnYjdcd").val();
	var url = "getZhdByKeyword.shtml";
	var obj = {keyword:keyword};
	if(keyword!=""){
		$.post(url,obj,getYJDCDCallbackForZhdn);
	}
}

function getYJDCDCallbackForZhdn(res){
	if(res!=""){
		$("#zhdnYjdcdRes").html("");
		res = eval(res);
		var str1 = '<option value="" selected="selected">--请选择--</option>';
		$("#zhdnYjdcdRes").append(str1);
		for(var i = 0;i<res.length;i++){
			var str = "";
			var type = top.getOperTypeZhdByCode(res[i].biaoshi)
			str = "<option value='"+res[i].id+"&"+res[i].biaoshi+"'>"+res[i].name+"("+type+")"+"</option>";
			$("#zhdnYjdcdRes").append(str);
		}
		$("#zhdnYjdcdRes").change(function(){
			$("#zhdnYjdcd").attr("value",res[$("#zhdnYjdcdRes").attr("selectedIndex")-1].name).attr("title",$("#zhdnYjdcdRes").val());
		});
	}
}

function zhdnQdButtonClick(){
	var jd = $("#zhdnJd").val();
	var wd = $("#zhdnWd").val();
	var gd = $("#zhdnGd").val();
	var dwsj = $("#zhdnDwsj").val();
	var zhdnTitle = $("#zhdnYjdcd").attr("title");
	var zhdbm = "";
	var biaoshi = "";
	if(zhdnTitle!=""||zhdnTitle!=null||zhdnTitle!=undefined){
		var zhdbm = $("#zhdnYjdcdRes").val().split("&")[0];
		var biaoshi = $("#zhdnYjdcdRes").val().split("&")[1];
	}
	if(jd==""||wd==""||gd==""||dwsj==""||zhdbm==""){
		alert("数据填写不完整！");
		return;
	}else{
		var obj = {jd:jd,wd:wd,gd:gd,zhdbm:zhdbm,dwsj:dwsj,biaoshi:biaoshi};
		var url = "insertWdwzForZhdn.shtml";
		$.post(url,obj,function(res){
			if(res=="true"){
				alert("插入成功!");
			}else{
				alert("插入失败!");
			}
		});
	}
}

